package com.web.websocket.interception;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.socket.server.HandshakeInterceptor;


import javax.websocket.HandshakeResponse;
import javax.websocket.server.HandshakeRequest;
import javax.websocket.server.ServerEndpointConfig;

@Slf4j
public class WebSocketInterception extends ServerEndpointConfig.Configurator {

    //允许哪些源 true 允许所有源
    @Override
    public boolean checkOrigin(String originHeaderValue) {
//        return super.checkOrigin(originHeaderValue);
        return true;
    }


    //这里做验证token之类的行为
    @Override
    public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
        log.debug("进入websocket拦截器！");

        //调用父类方法开始连接
        super.modifyHandshake(sec, request, response);
    }
}
